<template>
  <div>
    <el-header>
      <span>已有权限</span>
      <el-button @click="refresh">刷新消息</el-button>
    </el-header>
    <el-table
      :data="tableData.filter(data => !search||data.timestamp.includes(search) ||data.filename.includes(search.toLowerCase())||data.access.includes(search.toLowerCase()))"
      :default-sort="{prop:tableData.timestamp,order:'descending'}"
      style="width: 100%"
    >
      <el-table-column label="Date" prop="timestamp" sortable></el-table-column>
      <el-table-column label="Owner" prop="owner" sortable></el-table-column>
      <el-table-column label="File" prop="filename" sortable></el-table-column>
      <el-table-column label="Access" prop="access" sortable></el-table-column>
      <el-table-column label="Validity" prop="validity" sortable></el-table-column>
      <el-table-column align="right">
        <template slot="header" slot-scope="scope">
          <el-input v-model="search" size="mini" placeholder="输入关键字搜索" />
        </template>
        
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
export default {
  data() {
    return {
      requestType: {
        type: "give"
      },
      opInfo: {
        state: "refuse",
        messageId: "1"
      },
      tableData: [],
      search: ""
    };
  },
  mounted: function() {
    this.refresh();
  },
  methods: {
    refresh() {
      this.$axios.post("/home/getaccess", this.requestType).then(res => {
        // console.log(res.data);
        if (res.data.type === "success") {
          // console.log(res.data.content);
          this.tableData = res.data.content;
          // console.log(this.tableData)
        } else {
          this.$message({
            message: res.data.content,
            type: res.data.type
          });
        }
      });
    }
  }
};
</script>
<style scoped>
.el-header {
  background-color: #6d7981;
  display: flex;
  justify-content: space-between;
  color: #ffffff;
  font-size: 20px;
  align-items: center;
}
</style>